package com.xcity.game.treasurebox;

import java.util.List;

import com.xcity.game.item.ItemInfo;
import com.xcity.util.ArrayList;

import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.game.template.annotation.Binding;
import naga.x.game.template.annotation.Excel;

/**
 * 宝箱配置
 * @author yang.li
 *
 */
@Excel(value = "treasure_box.xlsx", sheet = 0)
public class TreasureBoxTemplate extends Template {

	/** 几率 */
	protected int weight;

	/** 物品1id */
	protected int[] items;
	
	protected List<ItemInfo> itemList;

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int[] getItems() {
		return items;
	}

	public void setItems(int[] items) {
		this.items = items;
	}
	
	public List<ItemInfo> getItemList() {
		return itemList;
	}
	
	public ItemInfo getItem(int index) {
		return itemList.get(index);
	}

	@Override
	public void validate() throws TemplateException {
		int len = items.length;
		ItemInfo[] ref = new ItemInfo[len >> 1];
		for (int i = 0, pos = 0; i < len; i += 2) {
			ref[pos++] = new ItemInfo(items[i], items[i + 1]);
		}
		itemList = new ArrayList<ItemInfo>(ref);
		items = null; // free
	}
}
